package com.xiaouyudeguang.common.handler;

import com.xiaouyudeguang.common.respose.ResultDto;
import com.zlyx.easy.core.utils.ResponseUtils;
import com.zlyx.easy.security.authentication.handler.DefaultAuthenticationFailureHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class AuthenticationFailureHandler extends DefaultAuthenticationFailureHandler {

    protected Logger logger = LoggerFactory.getLogger(AuthenticationFailureHandler.class);

    public void write(HttpServletResponse response, AuthenticationException e) throws IOException {
        this.logger.error(e.getMessage(), e);
        ResponseUtils.write(response, ResultDto.failure(e.getMessage()));
    }
}
